PV-on-HVM: Implement compatibilty version of wait_for_completion_timeout
authorIan Campbell <ian.campbell@xensource.com>
Wed, 25 Oct 2006 12:58:30 +0000 (13:58 +0100)
committerIan Campbell <ian.campbell@xensource.com>
Wed, 25 Oct 2006 12:58:30 +0000 (13:58 +0100)
for kernels before 2.6.11

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
unmodified_drivers/linux-2.6/compat-include/xen/platform-compat.h
unmodified_drivers/linux-2.6/platform-pci/platform-compat.c

index 185a97449c857d64c79db00b5627db111b83ba76..1026f9765375ca644148f6fd4e8477a5ce73c61e 100644 (file)
@@ -33,4 +33,8 @@
 unsigned long vmalloc_to_pfn(void *addr);
 #endif
 
+#if defined(__LINUX_COMPLETION_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
+unsigned long wait_for_completion_timeout(struct completion *x, unsigned long timeout);
+#endif
+
 #endif
index b79006bc219e4a1d5af0cd14458c06c18ea9c168..f13d54b15c80f2e07eaef43bc82ecd471a341817 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/sched.h>
 
 #include <xen/platform-compat.h>
 
@@ -41,3 +42,34 @@ unsigned long vmalloc_to_pfn(void * vmalloc_addr)
 }
 EXPORT_SYMBOL(vmalloc_to_pfn);
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
+unsigned long wait_for_completion_timeout(struct completion *x, unsigned long timeout)
+{
+        might_sleep();
+
+        spin_lock_irq(&x->wait.lock);
+        if (!x->done) {
+                DECLARE_WAITQUEUE(wait, current);
+
+                wait.flags |= WQ_FLAG_EXCLUSIVE;
+                __add_wait_queue_tail(&x->wait, &wait);
+                do {
+                        __set_current_state(TASK_UNINTERRUPTIBLE);
+                        spin_unlock_irq(&x->wait.lock);
+                        timeout = schedule_timeout(timeout);
+                        spin_lock_irq(&x->wait.lock);
+                        if (!timeout) {
+                                __remove_wait_queue(&x->wait, &wait);
+                                goto out;
+                        }
+                } while (!x->done);
+                __remove_wait_queue(&x->wait, &wait);
+        }
+        x->done--;
+out:
+        spin_unlock_irq(&x->wait.lock);
+        return timeout;
+}
+EXPORT_SYMBOL(wait_for_completion_timeout);
+#endif